package elibrary;

import java.io.*;
import java.util.StringTokenizer;

public class Config {
	public String connectURL;
	public String DBuser;
	public String DBpass;
	public void readConfig(String path) throws Exception{
		String str;
		try{
			// Open the file that is the first 
			// command line parameter
			FileInputStream fstream = new FileInputStream(path);

			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			//Read File Line By Line
			
			
			while ((strLine = br.readLine()) != null)   {
				// Print the content on the console
				
				StringTokenizer st = new StringTokenizer(strLine, "=");
				str = st.nextToken().trim();
				if(str.equals("String connectURL"))
					connectURL=st.nextToken().trim();
				if(str.equals("String DBuser"))
					DBuser=st.nextToken().trim();
				if(str.equals("String DBpass"))
					DBpass=st.nextToken().trim();
				
			}
			//Close the input stream
			in.close();
		}catch (Exception e){//Catch exception if any
			e.printStackTrace();
			throw e;
		}
	}
	public void writeConfig(String path, String text){
		try {
		      File file = new File(path);
		      FileWriter fw = new FileWriter(file); 
		      
		      fw.write(text);
		                   
		      fw.flush();  
		      fw.close();  
		      
		    } catch(IOException e) {
		    	e.printStackTrace(); 
		    }
	}
}